package com.thornbird.vehiclerecycling.config;

import com.thornbird.vehiclerecycling.controller.IndexController;
import com.thornbird.vehiclerecycling.exception.NotFoundException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice(assignableTypes = {IndexController.class})
public class PageExceptionHandler {

    @ExceptionHandler(value = MethodArgumentTypeMismatchException.class)
    public String errorHandler(HttpServletRequest request, MethodArgumentTypeMismatchException exception) {
        return "error/404";
    }

    @ExceptionHandler(value = NotFoundException.class)
    public String errorHandler(HttpServletRequest request, NotFoundException exception) {
        return "error/404";
    }

}
